import diff from "./diff"

export default function updateComponent(
    virtualDOM, 
    oldComponent, 
    oldDOM, 
    container
) {
    oldComponent.getDerivedStateFromProps()

    if(oldComponent.shouldComponentUpdate()) {
        let preProps = oldComponent.props
        // 组件更新
        oldComponent.updateProps(virtualDOM.props)
        // 获取组件返回得最新 virtualDOM
        let nextVirtualDOM = oldComponent.render()
        nextVirtualDOM.component = oldComponent

        diff(nextVirtualDOM, container, oldDOM)

        oldComponent.getSnapshotBeforeUpdate()
        oldComponent.componentDidUpdate(preProps)
    }
}